#include "MC.h"

#define memHandle
#define memStart
#define memSize


//All 4kb Aligned.
#define edgeStart
#define edgeEnd
#define edgeSize  (edgeEnd - edgeStart)

#define buffStart 
#define buffEnd
#define buffSize  (buffEnd - buffStart)

#define drvStart
#define drvEnd
#define drvSize   (drvEnd - drvStart)

#define _Malloc(size)  Kmalloc(memHandle,size)
#define _Free(ptr)     Kfree(memHandle,ptr)

#include "IFDInterface.h"
#include "memBlocks.h"

namespace IFD
{
  class ibuff
  {
  public:
    inline ibuff(const _length& _begin,const _length& _end,_ptlong _addr):begin(_begin),end(_end),addr(_addr){};
    inline ibuff(const _length& _begin,const _length& _end,_ptlong* _addr):begin(_begin),end(_end),addr(_addr){};
    inline ~ibuff();
    inline ibuff& combine(_length& a,_length& b);
    inline ibuff& apart(_length& a,_length& b);
    inline bool operator==(const ibuff& buffB) const
    {//shoot buff.
      return (((this->begin >= buffB.begin) && (this->begin <= buffB.end))
	      ||
	      ((this->end >= buffB.begin) && (this->end <= buffB.end)));
    }
    inline bool operator>(const ibuff& buffB) const
    {
      return (this->begin>buffB.begin);
    }
    inline bool operator<(const ibuff& buffB) const
    {
      return (this->begin<buffB.begin);
    }
    //  private:
    _length begin;
    _length end;
    _ptlong* addr;
  };

  typedef set<ibuff> ibuffs;
}
using IFDInterface::FRESULT;
  FRESULT BufferSync(IFD::ibuffs* _buffers,_ptlong* from,const _length& num,const _length& offset);
template<typename T>
FRESULT BufferGet(IFD::ibuffs* _buffers,_ptlong* to,const _length& num,const _length& offset,T read);
